package com.liang.lingdong.controller;

import com.liang.lingdong.common.BaseResponse;
import com.liang.lingdong.common.ErrorCode;
import com.liang.lingdong.common.ResultUtils;
import com.liang.lingdong.exception.BusinessException;
import com.liang.lingdong.model.signTopic.SignTopic;
import com.liang.lingdong.model.signTopic.dto.UserSubmitDto;
import com.liang.lingdong.model.signTopic.vo.SignTopicVo;
import com.liang.lingdong.service.SignTopicService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/examination")
public class SignTopicController {

    @Resource
    private SignTopicService signTopicService;


    /**
     * 用户提交题目
     */
    @PostMapping("/submit")
    public BaseResponse<Boolean> submit(@RequestBody UserSubmitDto userSubmitDto) {
        if (userSubmitDto == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean flag = signTopicService.userSubmit(userSubmitDto);
        return ResultUtils.success(flag);
    }

    /**
     * 获取我的答题卡
     */
    @GetMapping("/getMyAnswer")
    public BaseResponse<List<SignTopicVo>> getMyAnswer(Long signId) {
        if (signId == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        List<SignTopicVo> signTopics = signTopicService.getMyAnswer(signId);
        return ResultUtils.success(signTopics);
    }


    /**
     * 获取判题状态
     */
    @GetMapping("/getStatus")
    public BaseResponse<List<SignTopic>> getStatus(Long examId, Long topicId) {
        if (examId == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        List<SignTopic> signTopics = signTopicService.getStatus(examId, topicId);
        return ResultUtils.success(signTopics);
    }

}
